package com.haoran.dwz.domain.entities;

import javax.persistence.Transient;

import org.springframework.data.domain.Sort.Direction;

import com.haoran.dwz.common.xss.SQLFilter;

import io.swagger.annotations.ApiModelProperty;

public class PaginationEntity {

    @Transient
    @ApiModelProperty(value="偏移量 0 如果page有值优选取page值")
    private Integer offset = 0;

    @Transient
    @ApiModelProperty(value="每页大小 默认10")
    private Integer limit = 10;
    
    @Transient
    @ApiModelProperty(value="当前第几页 默认 1")
    private Integer page = 1; 
    
    @Transient
    @ApiModelProperty(value="排序字段;")
    private String sidx;
    
    @Transient
    @ApiModelProperty(value="排序方式 ASC, DESC;")
    private String order;
    
    public Direction getDirection() {
    	if("DESC".equalsIgnoreCase(getOrder())) {
    		return Direction.DESC;
    	}
    	return Direction.ASC;
    }
    
    public final Integer getPage() {
		return page;
	}

	public final void setPage(Integer page) {
		this.page = page;
	}

	public final Integer getOffset() {
        return offset;
    }

    public final void setOffset(Integer offset) {
        this.offset = offset;
    }

    public final Integer getLimit() {
        return limit;
    }

    public final void setLimit(Integer limit) {
        this.limit = limit;
    }

	public final String getOrder() {
		return SQLFilter.sqlInject(order);
	}

	public final void setOrder(String order) {
		this.order = order;
	}

	public final String getSidx() {
		return SQLFilter.sqlInject(sidx);
	}

	public final void setSidx(String sidx) {
		this.sidx = sidx;
	}
	
}